package com.carl.sysutil;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class StringUtil {
	
	private static final Logger logger = LoggerFactory.getLogger(StringUtil.class);
	public static final String LICENSE_KEY_IN_PROPERTIES = "licenselocation"; 
	public static ResourceBundle resourceBundle;
	
	public static String THE_ROLE_OF_USER_IS_SYS = "10000001";  //系统管理员
	public static String THE_SYSTEM_MANAGER_STRID = "Dsa.menu.systemManagerId";
	public static String THE_USER_MANAGER_STRID = "Dsa.menu.userManagerId";
	
	public static String THE_LICENSE_CHECK_ERROR = "00000001";  //证书校验失败
	
	public StringUtil(){
		resourceBundle = ResourceBundle.getBundle("../../../config");
	}
	
	/**
	 * 组合判断字符串是否为null，或者是空字符
	 * @param cs
	 * @return
	 */
	public static boolean isNotBlankEmpty(CharSequence cs){
		boolean isEmpty = StringUtils.isEmpty(cs);
		boolean isNull = StringUtils.isBlank(cs);
		
		if(isEmpty || isNull){
			return false;
		}else{
			return true;
		}
	}
	
	/**
	 * 获取配置文件中的配置参数，通过key
	 * @param key
	 * @return
	 */
	public String getValue(String key){
		
		if (!StringUtil.isNotBlankEmpty(key)) {
			logger.error("the input key is null!!!!!");
            return "";  
        }  
        String result = "";  
        try {  
            result = resourceBundle.getString(key);  
        }catch (MissingResourceException e) {  
        	logger.error("the getString(key) is error in running!!", e);
        }  
        return result;  
	}
}
